package com.kkb.controller;

import com.kkb.pojo.User;
import com.kkb.service.UserService;
import com.kkb.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author Lxy
 * @create 2022-03-24 17:58
 */

@RestController
public class PassController {

    @Resource
    private UserService userService;
    @RequestMapping(value = "/user/pass",method = RequestMethod.PUT)
    public ResultVo updatePass(String newpass, HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        int i = userService.updatePass(newpass, user);
        if (i == 1){
            return new ResultVo(200,"用户密码已成功更新");
        }
        return new ResultVo(500,"服务器内部出错,更新失败");
    }
}
